import { useIntersectionObserver } from "@vueuse/core";
import { ref } from "vue";
export function useObserver(apiFn: () => Promise<void>) {
  const target = ref(null);
  const { stop } = useIntersectionObserver(
    target,
    ([{ isIntersecting }], observerElement) => {
      if (isIntersecting) {
        stop();
        if (apiFn) {
          apiFn();
        }
      }
    },
  );
  return target;
}
